package com.houweishi.module.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.module.purchase.domain.OaPurchaseProduct;
import com.houweishi.module.purchase.service.IOaPurchaseProductService;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.common.core.page.TableDataInfo;

/**
 * 采购申请产品Controller
 * 
 * @author houweishi
 * @date 2023-03-27
 */
@RestController
@RequestMapping("/module/purchaseproduct")
public class OaPurchaseProductController extends BaseController
{
    @Autowired
    private IOaPurchaseProductService oaPurchaseProductService;

    /**
     * 查询采购申请产品列表
     */
    @PreAuthorize("@ss.hasPermi('module:purchaseproduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaPurchaseProduct oaPurchaseProduct)
    {
        startPage();
        List<OaPurchaseProduct> list = oaPurchaseProductService.selectOaPurchaseProductList(oaPurchaseProduct);
        return getDataTable(list);
    }

    /**
     * 导出采购申请产品列表
     */
    @PreAuthorize("@ss.hasPermi('module:purchaseproduct:export')")
    @Log(title = "采购申请产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaPurchaseProduct oaPurchaseProduct)
    {
        List<OaPurchaseProduct> list = oaPurchaseProductService.selectOaPurchaseProductList(oaPurchaseProduct);
        ExcelUtil<OaPurchaseProduct> util = new ExcelUtil<OaPurchaseProduct>(OaPurchaseProduct.class);
        util.exportExcel(response, list, "采购申请产品数据");
    }

    /**
     * 获取采购申请产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:purchaseproduct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(oaPurchaseProductService.selectOaPurchaseProductById(id));
    }

    /**
     * 新增采购申请产品
     */
    @PreAuthorize("@ss.hasPermi('module:purchaseproduct:add')")
    @Log(title = "采购申请产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaPurchaseProduct oaPurchaseProduct)
    {
        return toAjax(oaPurchaseProductService.insertOaPurchaseProduct(oaPurchaseProduct));
    }

    /**
     * 修改采购申请产品
     */
    @PreAuthorize("@ss.hasPermi('module:purchaseproduct:edit')")
    @Log(title = "采购申请产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaPurchaseProduct oaPurchaseProduct)
    {
        return toAjax(oaPurchaseProductService.updateOaPurchaseProduct(oaPurchaseProduct));
    }

    /**
     * 删除采购申请产品
     */
    @PreAuthorize("@ss.hasPermi('module:purchaseproduct:remove')")
    @Log(title = "采购申请产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaPurchaseProductService.deleteOaPurchaseProductByIds(ids));
    }
}
